package com.fr.cell.editor;

import com.fr.cell.event.CellEditorEvent;
import com.fr.cell.event.CellEditorListener;
import java.awt.Point;
import javax.swing.event.EventListenerList;

public abstract class AbstractCellEditor
  implements CellEditor
{
  private EventListenerList listenerList = new EventListenerList();
  private transient CellEditorEvent cellEditEvent = null;
  private transient Point locationOnCellElement = null;

  public Point getLocationOnCellElement()
  {
    return this.locationOnCellElement;
  }

  public void setLocationOnCellElement(Point paramPoint)
  {
    this.locationOnCellElement = paramPoint;
  }

  public boolean stopCellEditing()
  {
    fireEditingStopped();
    return true;
  }

  public void cancelCellEditing()
  {
    fireEditingCanceled();
  }

  public void addCellEditorListener(CellEditorListener paramCellEditorListener)
  {
    this.listenerList.add(CellEditorListener.class, paramCellEditorListener);
  }

  public void removeCellEditorListener(CellEditorListener paramCellEditorListener)
  {
    this.listenerList.remove(CellEditorListener.class, paramCellEditorListener);
  }

  protected void fireEditingStopped()
  {
    Object[] arrayOfObject = this.listenerList.getListenerList();
    for (int i = arrayOfObject.length - 2; i >= 0; i -= 2)
      if (arrayOfObject[i] == CellEditorListener.class)
      {
        if (this.cellEditEvent == null)
          this.cellEditEvent = new CellEditorEvent(this);
        ((CellEditorListener)arrayOfObject[(i + 1)]).editingStopped(this.cellEditEvent);
      }
  }

  protected void fireEditingCanceled()
  {
    Object[] arrayOfObject = this.listenerList.getListenerList();
    for (int i = arrayOfObject.length - 2; i >= 0; i -= 2)
      if (arrayOfObject[i] == CellEditorListener.class)
      {
        if (this.cellEditEvent == null)
          this.cellEditEvent = new CellEditorEvent(this);
        ((CellEditorListener)arrayOfObject[(i + 1)]).editingCanceled(this.cellEditEvent);
      }
  }
}